<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<%
String path = request.getContextPath();
// 获得项目完全路径:
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<head>
<meta charset="utf-8">
<title>云平台——开发者账号服务</title>
<meta http-equiv="pragma" content="no-cache">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="keywords" content="万达,服务,账号">
<meta http-equiv="description" content="开发者账号">
<meta http-equiv="cache-control" content="no-cache">
<link rel="shortcut icon" href="resources/images/logo/logo64.png"/>
<jsp:include page="pages/outerfile.jsp" flush="true" />
<style type="text/css">
	.login-container{
	display:none;
	}
	.login-container-bg{
		background:url(resources/images/login/login_bg.png) center  no-repeat;
		background-size:100% 100%;
		position: relative;
		
	}
	
	.main-contanier{
		width: 520px;
		height: 350px;
		position: absolute;
		left: 50%;
		top: 50%;
		margin-top: -180px;
		margin-left: -258px;
		background-image: url(resources/images/login/frame.png);
		background-size:100% 100%;
	}
	
	.main-contanier div{
		width:300px;
		margin-left:70px;
		
	}
	
	.main-contanier div.logo{
		height: 110px;
		margin-left:110px;
		text-align: center;
	}
	
	.main-contanier div.input{
		height: 48px;
		width:500px;
	}
	
	.main-contanier div.input span{
		position: relative;
		top: 10px;
		font-size: 13px;
	}
	
	.main-contanier div.input input{
		position: relative;
		top: 10px;
		left: 15px;
		width: 310px;
		height:30px;
		border: 1px solid #bfbfbf;
	}
	
	.main-contanier div.input input:focus{
		border: 1px solid #3D83F9;
	}
	
	.main-contanier div.input button{
   		 width: 310px;
   		 height: 30px;
		 /*background-image: url("resources/images/login/login_btn.png");*/
    	 position: relative;
   		 left: 52px;
   		 top: 25px;
   		 color:#fff;
   		 background-color:#0f9d58;
	}
	
	.main-contanier div.input button:hover{
		 /*background-image: url("resources/images/login/login_btn_hover.png");*/
		 background-color:#12b566;
	}
	
	.main-contanier div.input img{
		position: relative;
		top: 10px;
		left: 15px;
	}
	.main-contanier div.logo img{
		width: 90px;
		margin-top: 20px;
	}
	.user_retrieve{
		color: #FF6633;
	}
	.user_retrieve:hover{
		color:#FF9999;
	}
	.navbar-footer{
		width: 100%;
		height: 50px;
    	line-height: 50px;
		margin:0px auto;
		background-color:#34495E;
		color:white;
		text-align: center;
		position:absolute;bottom:0;
	}
</style>
<script type="text/javascript">
    function firstLoad(){
    		if("${datas}"!=""){
    			window.location.href="${pageContext.request.contextPath}/index.jsp";
    		}else{
    			var loginNum=sessionStorage.getItem("loginNum");
	   			if(loginNum!=""&&loginNum!==null&&loginNum=="login"){
	   				sessionStorage.setItem("loginNum",null);
	   				window.location.reload(true);
	   			}else{
	    			document.getElementById('checkupdate').style.display="block";
	   			}
    		}
    }
	function check(){
		sessionStorage.clear();
		var windowWidth = $("#alertDialog").width();
		if(windowWidth==400){
			//alert(windowWidth)
			var pwd = $('#login-pass').val();
			var name = $('#login-name').val();
			var code=$("#identif-code").val(); 
		    var keepLogin = $("#keepLoginCheck").is(":checked");
			if ("" == name) {
				createAlertWindow("用户名不能为空！");
				$("#login-name").focus();
				return false;
			} else if ("" == pwd) {
				createAlertWindow("密码不能为空！");
				$("#login-pass").focus();
				return false;
			} else if ("" == code) {
				createAlertWindow("验证码不能为空！");
				$("#identif-code").focus();
				return false;
			}else {
				 pwd=$.md5(pwd);
				 $.post("user/login",{
	             userName:name,
	             userPassword:pwd,
	             code:code,
	             keepLogin:keepLogin
	         },function(msg){
		        	if(msg.code == 1){
		        			sessionStorage.setItem("loginNum","login");
		        			if(msg.userName===""||msg.userName===null){
		        				createAlertWindow("是否设置用户名？",true,function(r){
		        					if(r){
		        						window.location="<%=basePath%>index.jsp";
		        					}
		        				})
		        			}
		        			window.location="<%=basePath%>index.jsp";
		        	}else{
		        		if(msg.msg.trim() == "wrong Password or wrong userName"){
							createAlertWindow("用户名密码不匹配！");
							$("#login-name").focus();
						}else if(msg.msg.trim() == "User account is locked"){
							createAlertWindow("该用户已锁定，请联系管理员！");
							$("#login-name").focus();
						}else if(msg.msg.trim()=="wrong captchaCode"){
							createAlertWindow("验证码输入有误");
							$("#identif-code").focus();
							$('#identif-code').val("");
						}else{
							createAlertWindow(msg.msg);
						}
		        		//reset();
		        		identifpic();
		        	}
		    }); 
				return true;
			}
		}
				
			
			
		
	
	}
	
	function reset(){	
		$('#login-name').val("");
		$('#login-pass').val("");
		$('#identif-code').val("");
	}
	function getQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) {
			return unescape(r[2]);
		}
		return null;
	}
	function loginwindow(){
		$('#alertDialog').css('width','400');
	}
	<%-- function init() {
		$("#identif-code").val("");
		if (getQueryString('error') != null) {
			var exception_value = '<%=session.getAttribute("SPRING_SECURITY_LAST_EXCEPTION")%>';
			if("null" != exception_value){
				var exception_keyword = exception_value.split(":")[1];
				if(exception_keyword.trim() == "Bad credentials"){
					createAlertWindow("用户名密码不匹配！");
				}else if(exception_keyword.trim() == "User account is locked"){
					createAlertWindow("该用户已锁定，请联系管理员！");
				}else{
					createAlertWindow(exception_keyword);
				}
			}
		};
	} --%>
	function identifpic(){
 		 var date=new Date();
 		 var src = "user/identfycode/getcode?date="+date;
 	     $("#identifcodepic").attr("src",src);
	}
	$(function(){
		firstLoad();
		document.onkeydown=function mykeyDown(e){  
	      //compatible IE and firefox because there is not event in firefox  
	       e = e||event;  
	      
	       if(e.keyCode == 13) {
	    	   if($('#alertDialog').width()==100){
				
				$('#alertDialog').css('width','400');
				$('#alertDialog').empty();
				}
				else
				{
				//	alert(222)
					check();
				}
	       }   
	       return;  
	
		};
	})
</script>
</head>
<body> 
 <div class="login-container" id="checkupdate">
 	<div class="login-container-bg">
		<div class="main-contanier" >
			<div class="logo">
				<img src="resources/images/logo/logo.png"/>
			</div>
			<div class="input">
				<span>用户名</span><input id="login-name" />
			</div>
			<div class="input">
				<span>密&nbsp;&nbsp;&nbsp;码</span><input type="password" id="login-pass"/>
			</div>
			<div class="input">
				<span>验证码</span><input id="identif-code" style="width: 190px;"/>
				<img id="identifcodepic" onclick="identifpic()"  src="user/identfycode/getcode" style="width: 90px;height: 33px;">
                <a href="#"><img onclick="identifpic()"  src="resources/images/login/refresh.png" width="13px"></a>
			</div>
			<div class="input">
				<button id="login_button" onclick="check()" style="margin-left:2px;border:0;outline:none">登&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;录</button>
			</div>
			<div class="input">
				<a href="regist.jsp" class="user_retrieve" style="position:relative;top:0px;left:55px; text-decoration:underline;font-size: 15px;">注册账号</a>
				<a href="pages/retrievePwd1.jsp" class="user_retrieve" style="position:relative;top:0px;left:240px; text-decoration:underline;font-size: 15px;">忘记密码</a>
			</div>
		</div>
 	</div>
 	<div class="navbar-footer" >
		©2014 开发者中心 &nbsp;&nbsp;|&nbsp;&nbsp;服务协议&nbsp;&nbsp;|&nbsp;&nbsp;权利声明
	</div>
 </div>
 <div id="alertDialog" style="height: 0px;width:400px;"class="win_dialog">
  </div> 
  <%
  		//session.invalidate();
   %>
  <script type="text/javascript">
  
  	function changeSize(){
  		$(".login-container").height($(window).height());
 		$(".login-container").width($(window).width());
 		$(".login-container-bg").height($(window).height()-$(".navbar-footer").height());
 		$(".login-container-bg").width($(window).width());
  	}
  
 	$(function(){

 		reset();
 		changeSize();
 		window.onresize=function(){
 			changeSize();
 		};
 		
/*  		$("#login-name").keydown(function(e){
			if(e.keyCode==13) {
				e.preventDefault();
				$("#login-pass").focus();//处理事件
		     }
		}); 
		$("#login-pass").keydown(function(e){
			if(e.keyCode==13) {
				e.preventDefault();
				if($('#alertDialog').width()==100){
					$('#alertDialog').css('width','400')
					$('#alertDialog').empty();
				}
				else{check();}
				//处理事件
		     }
		}); */
 		/* init(); */
 	});
	</script>  
</body>
</html>
